<?php

class Gmapsprofile_View_Helper_GmapsprofileBlock extends Zend_View_Helper_Abstract {
	
	public function gmapsprofileBlock($subject, $label = false, $viewer = null) {
		$class = $label ? 'buttonlink' : 'buttonlink_members_gmap';
		
		if (null === $viewer) {
			$viewer = Engine_Api::_ ()->user ()->getViewer ();
		}
		
		// Can't block self or if not logged in
		if (! $viewer->getIdentity () || $viewer->getGuid () == $subject->getGuid ()) {
			return false;
		}
		
		if (! Engine_Api::_ ()->authorization ()->isAllowed ( 'user', $viewer, 'block' )) {
			return false;
		}
		
		if (! $subject->isBlockedBy ( $viewer )) {
			$label = ! $label ? '' : $this->view->translate ( 'Block Member' );
			return $this->view->htmlLink ( array ('route' => 'user_extended', 'controller' => 'block', 'action' => 'add', 'user_id' => $subject->user_id ), $label, array ('class' => $class . ' icon_block', 'title' => $this->view->translate ( 'Block Member' ), 'onclick' => "parent.Smoothbox.open(this.href); return false;" ) );
		
		} 

		else {
			$label = ! $label ? '' : $this->view->translate ( 'Unblock Member' );
			return $this->view->htmlLink ( array ('route' => 'user_extended', 'controller' => 'block', 'action' => 'remove', 'user_id' => $subject->user_id ), $label, array ('class' => $class . ' icon_unblock', 'title' => $this->view->translate ( 'Unblock Member' ), 'onclick' => "parent.Smoothbox.open(this.href); return false;" ) );
		}
	}

}